package com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.ctrl;

import static org.mockito.ArgumentMatchers.any;

import java.util.HashMap;
import java.util.Map;

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.testng.annotations.Test;

import com.flux.tms.tm${bean.numMain}srv.common.ctrl.CommonCtrl;
import com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.${bean.pk05}CVal;
import com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.service.${bean.serviceName};
import com.flux.wmsv5.comobjs.CommonCVal;
import com.flux.wmsv5.comobjs.LoginInfoObj;

public class ${bean.fileName}Test extends CommonCtrl{
@InjectMocks
private ${bean.fileName} ${bean.fileName};
@Mock
private ${bean.serviceName} ${bean.serviceName};

@Override
protected CommonCtrl returnSubClass() {
    return this;
}

@Override
protected void initSubLogin() {

}

@Override
protected void initSubBizDataMap() {
    String[] wantCheckIdsForBizData = { CommonCVal.KEYNAME_DATASIGNATURE,
        ${bean.pk05}CVal.KEYNAME_ORGANIZATIONID,
        ${bean.pk05}CVal.KEYNAME_DISPATCHZONECODE
    };
    for(String key : wantCheckIdsForBizData){
        bizDataMap.put(key, "123");
    }
}

@Test
public void test() throws Exception {
    init();
    //测试登录对象无数据
    loginNoData();
    //测试业务数据字典无数据
    initLogin();
    bizDataNoData();
    initBizDataMap();
    reObj.setCodeValueOK();
    reObj.setMessageId("123");
    //测试其他
    testOther();
    //测试正常
    testOK();
}

@Override
protected void loginNoDataSub(String loginInfo, String bizData) {
    ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});
    spy.doAction(loginInfo, bizData);
}

@Override
protected void bizDataNoDataSub(String loginInfo, String bizData) {
    ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});
    spy.doAction(loginInfo, bizData);
}

@SuppressWarnings("unchecked")
@Override
protected void testOtherSub(String loginInfo, String bizData) throws Exception {
        ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});

       //测试tariffBasedCalculate=Y
      //bizDataMap.put(${bean.pk05}CVal.KEYNAME_TARIFFBASEDCALCULATE, "Y");
        bizData = bizDataMapToString();
        spy.doAction(loginInfo, bizData);
        //测试KEYNAME_CHARGETYPE、KEYNAME_RATEQTY1、KEYNAME_RATEQTY2有值
      //bizDataMap.put(${bean.pk05}CVal.KEYNAME_CHARGETYPE, "A");
      //bizDataMap.put(${bean.pk05}CVal.KEYNAME_RATEQTY1, "1");
      //bizDataMap.put(${bean.pk05}CVal.KEYNAME_RATEQTY2, "2");
        bizData = bizDataMapToString();
        spy.doAction(loginInfo, bizData);


        Map<String, Object> dataMap = new HashMap<String, Object>();
       //dataMap.put(${bean.pk05}CVal.KEYNAME_LINENUMBER, "0");
        bizDataMap.put(CommonCVal.KEYNAME_ORGANIZATIONID, "FLUX");
        bizDataMap.put(CommonCVal.ACT_IMP, "Y");
        bizData = bizDataMapToString();
       //PowerMockito.doReturn(null).when(${bean.serviceName}).getMaxLineNumber(any(LoginInfoObj.class), any(Map.class));
       //PowerMockito.doReturn(dataMap).when(${bean.serviceName}).getAsnDocFee(any(LoginInfoObj.class), any(Map.class));
        spy.doAction(loginInfo, bizData);

        bizDataMap.remove(CommonCVal.ACT_IMP);
        bizData = bizDataMapToString();
        spy.doAction(loginInfo, bizData);

      //PowerMockito.doReturn(dataMap).when(${bean.serviceName}).getMaxLineNumber(any(LoginInfoObj.class), any(Map.class));
      //PowerMockito.doReturn(null).when(${bean.serviceName}).getAsnDocFee(any(LoginInfoObj.class), any(Map.class));
        spy.doAction(loginInfo, bizData);

        //        dataMap.put(${bean.pk05}CVal.KEYNAME_LINENUMBER, "1");
        //        PowerMockito.doReturn(dataMap).when(${bean.serviceName}).getMaxLineNumber(any(LoginInfoObj.class), any(Map.class));
        spy.doAction(loginInfo, bizData);

        //postDataWithExtend resultObj 返回 false
        reObj.setCodeValueOK();
//        try {
//            PowerMockito.doReturn(reObj).when(${bean.serviceName}).postDataWithExtend(any(String.class),any(String.class), any(Map.class), any(LoginInfoObj.class), any(ResultObj.class));
//            spy.doAction(loginInfo, bizData);
//            //测试正常
//            //测试返回仓库
//            testOKSub(loginInfo, bizData);
//        } catch (Exception e) {
//        }
}

@SuppressWarnings("unchecked")
@Override
protected void testOKSub(String loginInfo, String bizData) throws Exception {
    initSub();
    ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});
// 自己开始写postData的测试，因为部分的postData的参数个数不一，注意参数的数量；
   // PowerMockito.doReturn(reObj).when(${bean.serviceName}).postData(any(LoginInfoObj.class), any(Map.class));
    spy.doAction(loginInfo, bizData);
}

@Override
protected void initSub() throws Exception {

}

}
